package diaosidadui.test2;

public class Test04 {
    /*
    求数组中的最大 最小
     */
    public static void main(String[] args) {
        int[] arr = {321, 54, 74, 7, 43, 23, 77, 44, 652, 3435, 54};

/*        System.out.println("最小值:" + getMinAndMax(arr)[0]);
        System.out.println("最大值:" + getMinAndMax(arr)[1]);*/

        int[] arr2 = getMinAndMax(arr);
        System.out.println(arr2[0]);
        System.out.println(arr2[1]);

    }


    public static int[] getMinAndMax(int[] a) {
        int min = a[0];
        int max = a[0];
        for (int i = 0; i < a.length; i++) {
            //a[i]
            min = min < a[i] ? min : a[i];
            max = max > a[i] ? max : a[i];
        }

        int[] arr = {min, max};
        return arr;
    }


}
